package cn.cttic.system.dubbo;

import cn.cttic.common.core.constant.CacheNames;
import cn.cttic.common.redis.utils.RedisUtils;
import cn.cttic.system.domain.SysConfig;
import cn.hutool.core.convert.Convert;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import cn.cttic.system.api.RemoteConfigService;
import cn.cttic.system.service.ISysConfigService;
import org.springframework.stereotype.Service;

/**
 * 配置服务
 *
 * @author Michelle.Chung
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteConfigServiceImpl implements RemoteConfigService {

    private final ISysConfigService configService;

    /**
     * 获取注册开关
     */
    @Override
    public boolean selectRegisterEnabled(String tenantId) {
        return configService.selectRegisterEnabled(tenantId);
    }

    @Override
    public String selectConfig(String configName) {
        String configVal;
        try {
            configVal = RedisUtils.getCacheMapValue(CacheNames.SYS_CONFIG, configName);
            return configVal;
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        configVal = configService.selectConfigByKey(configName);
        return configVal;
    }

}
